home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * ascope.c -
- *
- * cc -o ascope ascope.c -lgl_s -laudio
- */
-
- #include <audio.h>
- #include <gl.h>
- #include <gl/device.h>
-
- #define BUF_LEN 2205
-
- static void draw_buffer(short *, int);
-
- main()
- {
- int done = 0;
- int bufferLength = BUF_LEN;
- short *sampleBuffer;
- ALport port;
- long dev;
- short val;
-
- /*
- * old-style GL initialization code
- */
- prefsize(500, 250);
- winopen("scope");
- ortho2(0.0, (float)bufferLength, -32767.0, 32767.0);
- doublebuffer();
- gconfig();
- qdevice(ESCKEY);
-
- /*
- * the 0-valued ALconfig provides us with the default
- * settings for port (100,000 sample queue, stereo input,
- * 16-bit data).
- */
- port = ALopenport("scope input", "r", (ALconfig)0);
- if (port == (ALport) 0) {
- printf("failed to open the audio port\n");
- exit(-1);
- }
-
- /*
- * allocate enough buffer space for bufferLength frames of stereo
- * data.
- */
- sampleBuffer = (short *)malloc(sizeof(short) * 2 * bufferLength);
- if (sampleBuffer == (short *) 0) {
- printf("yikes...malloc failed...abort.\n");
- exit(-1);
- }
-
- while (!done)
- {
- if (qtest()) {
- dev = qread(&val);
- if (dev == ESCKEY) {
- done = 1;
- }
- }
- ALreadsamps(port, sampleBuffer, 2 * bufferLength);
- draw_buffer(sampleBuffer, bufferLength);
- }
- ALcloseport(port);
- exit(1);
- }
-
- static void
- draw_buffer(short *sample, int length)
- {
- int i;
- float vert[2];
-
- /* background */
- color(8);
- clear();
-
- /* grid */
- color(0);
- for (i = 1; i < 10; i++) {
- bgnline();
- vert[0] = (float) length * (float) i / 10.0;
- vert[1] = -32767.0;
- v2f(vert);
- vert[1] = 32767.0;
- v2f(vert);
- endline();
- }
- for (i = 1; i < 6; i++) {
- bgnline();
- vert[0] = 0.0;
- vert[1] = -32767.0 + 65534 * (float) i / 6.0;
- v2f(vert);
- vert[0] = (float) length;
- v2f(vert);
- endline();
- }
-
- /* draw the waveform for the left channel data */
- color(GREEN);
- bgnline();
- for (i = 0; i < length; i++)
- {
- vert[0] = (float) i;
- vert[1] = (float) sample[2*i];
- v2f(vert);
- }
- endline();
- swapbuffers();
- }
-